1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.IO;
6 using System.Drawing;
7 using System.Linq;
8 using System.Text;
9 using System.Windows.Forms;
10 using System.Data.SqlClient;
11 using System.Data.Sql;
12 using System.Data.SqlTypes;
13 using MySql.Data.MySqlClient;
14 using MySql.Data.Entity;
15 using MySql.Data.Types;
16 using MySql.Data;
17
18 namespace PhoneDirectory
19 {
20 public partial class Form1 : Form
21 {
22 public Form1()
23 {
24 InitializeComponent();
25 }
26 static string name;
27 private void Form1_Load(object sender, EventArgs e)
28 {
29 loadData();
30 }
31 private void loadData()
32 {
33 using (MySqlConnection conn = new MySqlConnection("server=localhost;user=root;database=phonedirectory;port=3306;password=;"))
34 {
35 using (MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT Name,Nickname,PhoneNumber,MobileNumber,EmailAddress,HomeAddress,Company,Position,GroupName,Website,FacebookAccount From directory Where Remarks=''", conn))
36 {
37 DataSet ds = new DataSet();
38 adapter.Fill(ds);
39 dataGridView1.DataSource = ds.Tables[0];
40 }
41 }
42 }
43
44 private void loadData(string searcher, string field)
45 {
46 name = searcher;
47 if (comboBox1.Text == "")
48 {
49 try
50 {
51 using (MySqlConnection conn = new MySqlConnection("server=localhost;user=root;database=phonedirectory;port=3306;password=;"))
52 {
53 using (MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT Name,Nickname,PhoneNumber,MobileNumber,EmailAddress,HomeAddress,Company,Position,GroupName,Website,FacebookAccount From directory WHERE Name LIKE '%" + name +
54 "%' or Nickname LIKE '%"+name+
55 "%' or PhoneNumber LIKE '%" + name +
56 "%' or MobileNumber LIKE '%" + name +
57 "%' or EmailAddress LIKE '%" + name +
58 "%' or HomeAddress LIKE '%" + name +
59 "%' or Company LIKE '%" + name +
60 "%' or Position LIKE '%" + name +
61 "%' or GroupName LIKE '%" + name +
62 "%' or Website LIKE '%" + name +
63 "%' or FacebookAccount LIKE '%" + name + "%'", conn))
64 {
65 DataSet ds = new DataSet();
66 adapter.Fill(ds);
67 dataGridView1.DataSource = ds.Tables[0];
68
69
70 }
71 }
72 }
73 catch (Exception er)
74 {
75 }
76 }
77 else
78 {
79 try
80 {
81 using (MySqlConnection conn = new MySqlConnection("server=localhost;user=root;database=phonedirectory;port=3306;password=;"))
82 {
83 using (MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT Name,Nickname,PhoneNumber,MobileNumber,EmailAddress,HomeAddress,Company,Position,GroupName,Website,FacebookAccount From directory WHERE " + field + " LIKE '%" + textBox1.Text + "%'", conn))
84 {
85 DataSet ds = new DataSet();
86 adapter.Fill(ds);
87 dataGridView1.DataSource = ds.Tables[0];
88 }
89 }
90 }
91 catch (Exception er)
92 {
93 }
94 }
95
96 }
97
98 private void textBox1_TextChanged(object sender, EventArgs e)
99 {
100
101 }
102
103 private void button1_Click(object sender, EventArgs e)
104 {
105 loadData();
106 textBox1.Text= "";
107 comboBox1.Text = "";
108 }
109
110 private void toolStripMenuItem1_Click(object sender, EventArgs e)
111 {
112 frm_dev a = new frm_dev();
113 a.ShowDialog();
114 }
115
116 private void textBox1_TextChanged_1(object sender, EventArgs e)
117 {
118 loadData(textBox1.Text, comboBox1.Text);
119 }
120
121 static string Name1;
122 static string Nickname;
123 static string PhoneNumber;
124 static string MobileNumber;
125 static string EmailAddress;
126 static string HomeAddress;
127 static string Company;
128 static string Position;
129 static string GroupName;
130 static string Website;
131 static string FacebookAccount;
132
133 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
134 {
135 try
136 {
137 int index = e.RowIndex;
138 DataGridViewRow selectedRow = dataGridView1.Rows[index];
139 Name1 = selectedRow.Cells[0].Value.ToString();
140 Nickname = selectedRow.Cells[1].Value.ToString();
141 PhoneNumber = selectedRow.Cells[2].Value.ToString();
142 MobileNumber = selectedRow.Cells[3].Value.ToString();
143 EmailAddress = selectedRow.Cells[4].Value.ToString();
144 HomeAddress = selectedRow.Cells[5].Value.ToString();
145 Company = selectedRow.Cells[6].Value.ToString();
146 Position = selectedRow.Cells[7].Value.ToString();
147 GroupName = selectedRow.Cells[8].Value.ToString();
148 Website = selectedRow.Cells[9].Value.ToString();
149 FacebookAccount = selectedRow.Cells[10].Value.ToString();
150
151 frm_prev a = new frm_prev(Name1,Nickname,PhoneNumber,MobileNumber,EmailAddress,HomeAddress,Company,Position,GroupName,Website,FacebookAccount);
152 a.ShowDialog();
153 loadData();
154
155 }
156 catch (Exception er)
157 {
158 }
159 }
160
161 private void toolStripMenuItem2_Click(object sender, EventArgs e)
162 {
163
164 }
165
166 private void toolStripMenuItem3_Click(object sender, EventArgs e)
167 {
168 frm_add a = new frm_add();
169 a.ShowDialog();
170 loadData();
171 }
172
173 private void toolStripMenuItem1_Click_1(object sender, EventArgs e)
174 {
175 frm_dev a = new frm_dev();
176 a.ShowDialog();
177 }
178
179 private void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e)
180 {
181
182 }
183
184 private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
185 {
186
187 }
188 }
189 }